
const db = require('db');
const log = require('tools/log');

module.exports = async ctx => {
    const { connection, comply } = db.init();

    try {
        const id = ctx.params.id;
        await delInfo(id, comply);
        await delSettlement(id, comply);
        ctx.body = 'ok';
        ctx.status = 200;
    } catch (error) {
        log('---------------------------------------------------')
        console.log(error);
        ctx.status = 500;
        ctx.body = error;
    }

    connection.end();
}


/** 删除数据 */
async function delInfo(id, comply) {
    await comply(`
        UPDATE orders SET orderStatus='等待下单',deptName=null,deptId=null,startTime=null,completionTime=null,pmId=null,pmName=null,company=null
        WHERE id = ${id}
    `)
}

/** 删除结算明细 */
async function delSettlement(id, comply) {
    await comply(`
        DELETE FROM settlementEntry 
        WHERE ordersId = ${id}
    `)
}